package net.mihome.app.bean;

import com.easemob.chat.EMContact;

import net.mihome.app.bean.net.ResponsePojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 登录用户实体类
 * @author liux (http://my.oschina.net/liux)
 * @version 1.0
 * @created 2012-3-21
 */
public class User extends EMContact {

    private String header;
    private int unreadMsgCount;
	public final static int	RELATION_ACTION_DELETE = 0x00;//取消关注
	public final static int	RELATION_ACTION_ADD = 0x01;//加关注
	
	public final static int	RELATION_TYPE_BOTH = 0x01;//双方互为粉丝
	public final static int	RELATION_TYPE_FANS_HIM = 0x02;//你单方面关注他
	public final static int	RELATION_TYPE_NULL = 0x03;//互不关注
	public final static int	RELATION_TYPE_FANS_ME = 0x04;//只有他关注我
	
	private String token;
	private int uid;
	private String location;
	private String name;
	private int followers;
	private int fans;
	private int score;
	private String face;
	private String account;
	private String pwd;
    private String communityName;
    private Integer communityId;
	private Result validate;
	private boolean isRememberMe;
	private String openId;
	private String jointime;
	private String gender;
	private String devplatform;
	private String expertise;
	private int relation;
	private String latestonline;
    private String realName;
    private String address;
    private String markName;
    private String markEmail;
    private String markQq;
    private String markPhoneNum;
    private String markAddress;
    private String mobile;
    private Community community;

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public boolean isRememberMe() {
		return isRememberMe;
	}
	public void setRememberMe(boolean isRememberMe) {
		this.isRememberMe = isRememberMe;
	}
	public String getJointime() {
		return jointime;
	}
	public void setJointime(String jointime) {
		this.jointime = jointime;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public String getDevplatform() {
		return devplatform;
	}
	public void setDevplatform(String devplatform) {
		this.devplatform = devplatform;
	}
	public String getExpertise() {
		return expertise;
	}
	public void setExpertise(String expertise) {
		this.expertise = expertise;
	}
	public int getRelation() {
		return relation;
	}
	public void setRelation(int relation) {
		this.relation = relation;
	}
	public String getLatestonline() {
		return latestonline;
	}
	public void setLatestonline(String latestonline) {
		this.latestonline = latestonline;
	}
	public int getUid() {
		return uid;
	}
	public void setUid(int uid) {
		this.uid = uid;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getFollowers() {
		return followers;
	}
	public void setFollowers(int followers) {
		this.followers = followers;
	}
	public int getFans() {
		return fans;
	}
	public void setFans(int fans) {
		this.fans = fans;
	}
	public int getScore() {
		return score;
	}
	public void setScore(int score) {
		this.score = score;
	}
	public String getFace() {
		return face;
	}
	public void setFace(String face) {
		this.face = face;
	}
	public Result getValidate() {
		return validate;
	}
	public void setValidate(Result validate) {
		this.validate = validate;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	
	public static User parse(Map map){
		User user=new User();
		Double idl=(Double) map.get("id");
		user.setUid(idl.intValue());


        Double communityIdd=(Double) map.get("community_id");
        if(communityIdd!=null){
            user.setCommunityId(communityIdd.intValue());
        }

		user.setAccount((String) map.get("username"));
        user.setUsername((String) map.get("username"));
		user.setCommunityName((String) map.get("community_name"));
		user.setOpenId((String) map.get("open_id"));
		user.setFace((String) map.get("avatar"));
		user.setRealName((String) map.get("realname"));
		user.setAddress((String) map.get("address"));
        if(map.get("sex")!=null){
            Double sex=(Double) map.get("sex");
            if(sex!=null){
                int sexi=sex.intValue();
                user.setGender((sexi==0)?"男":"女");
            }
        }
		user.setJointime((String) map.get("create_at"));
		user.setName((String) map.get("username"));
        //获取备注信息
        if(map.get("mark_name")!=null){
            user.setMarkName((String) map.get("mark_name"));
        }
        if(map.get("mark_phone_num")!=null){
            user.setMarkPhoneNum((String) map.get("mark_phone_num"));
        }
        if(map.get("mark_address")!=null){
            user.setMarkAddress((String) map.get("mark_address"));
        }
        if(map.get("mark_email")!=null){
            user.setMarkEmail((String) map.get("mark_email"));
        }
        if(map.get("mark_qq")!=null){
            user.setMarkQq((String) map.get("mark_qq"));
        }
        if(map.get("community")!=null){
            user.setCommunity(Community.parse((Map) map.get("community")));
        }
        user.setMobile((String) map.get("mobile"));
		return user;
	}

    public static List<User> parserList(ResponsePojo<List<Map>> responsePojo){
        List<User> list=new ArrayList<User>();
        if(responsePojo!=null&&responsePojo.getData()!=null){
            Iterator<Map> iterator=responsePojo.getData().iterator();
            while(iterator.hasNext()){
                Map map=iterator.next();
                User user=parse(map);
                list.add(user);
            }
        }
        return list;
    }
    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public int getUnreadMsgCount() {
        return unreadMsgCount;
    }

    public void setUnreadMsgCount(int unreadMsgCount) {
        this.unreadMsgCount = unreadMsgCount;
    }

    public String getCommunityName() {
        return communityName;
    }

    public void setCommunityName(String communityName) {
        this.communityName = communityName;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public Integer getCommunityId() {
        return communityId;
    }

    public void setCommunityId(Integer communityId) {
        this.communityId = communityId;
    }

    public String getMarkName() {
        return markName;
    }

    public void setMarkName(String markName) {
        this.markName = markName;
    }

    public String getMarkEmail() {
        return markEmail;
    }

    public void setMarkEmail(String markEmail) {
        this.markEmail = markEmail;
    }

    public String getMarkQq() {
        return markQq;
    }

    public void setMarkQq(String markQq) {
        this.markQq = markQq;
    }

    public String getMarkPhoneNum() {
        return markPhoneNum;
    }

    public void setMarkPhoneNum(String markPhoneNum) {
        this.markPhoneNum = markPhoneNum;
    }

    public String getMarkAddress() {
        return markAddress;
    }

    public void setMarkAddress(String markAddress) {
        this.markAddress = markAddress;
    }

    public Community getCommunity() {
        return community;
    }

    public void setCommunity(Community community) {
        this.community = community;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
}
